﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Cemit.PolyServer.Login
{
    class LoginServer : PolyServer
    {
        List<ClientState> players = new List<ClientState>();

        [ReceiveDynamicMsg("login")]
        private dynamic OnLogin(DynamicMsgData data)
        {
            if (data.msg.password == "123456")
            {
                foreach (var player in players)
                {
                    player.SendDynamicMsg("NewPlayer", new { account = data.msg.account });
                }

                players.Add(data.clientState);
                data.clientState.OnClosed += client => players.Remove(client);
                return "登录成功";
            }
            else
            {
                return "登录失败";
            }
        }
    }
}
